﻿Imports System.Windows.Controls

''' <summary>
''' Permet de choisir le bon datatemplate
''' </summary>
''' <remarks></remarks>
Public Class EditorSelector
    Inherits DataTemplateSelector

    Private Shared Templates As Windows.ResourceDictionary

    Shared Sub New()
        Templates = New Windows.ResourceDictionary()
        Templates.Source = New Uri("/OMANE.Modules.CRT;component/Ressources/ParametrageTemplates.xaml", System.UriKind.Relative)
    End Sub

    Public Overrides Function SelectTemplate(ByVal item As Object, ByVal container As System.Windows.DependencyObject) As System.Windows.DataTemplate
        Try
            Dim elt As VMParametrageElement = item
            If elt.Type = "yesno" Then
                Return Templates("yesnoeditor")
            End If
            If elt.Type = "selector" Then
                Return Templates("selectoreditor")
            End If
            If elt.Type = "multiselector" Then
                Return Templates("multiselectoreditor")
            End If
            If elt.Type = "fileselector" Then
                Return Templates("fileselectoreditor")
            End If
            If elt.Type = "folderselector" Then
                Return Templates("folderselectoreditor")
            End If
            If String.IsNullOrEmpty(elt.Editor) Then
                Return Templates("defaulteditor")
            End If

            Return Nothing
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
End Class